package com.cyandpos.pad.cateringformat.opentable;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.common.commondata.CateringPosConstant;
import com.cyandpos.pad.posdata.DinnerTable;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xin on 2021/8/31
 * desc:
 */
public class OpenTableGridAdapter extends BaseAdapter {
    private Context context;
    private List<DinnerTable> tables = new ArrayList<DinnerTable>();

    public OpenTableGridAdapter(Context mContext,List<DinnerTable> mSkfs) {
        super();
        this.context = mContext;
        this.tables = mSkfs;
    }

    @Override
    public int getCount() {
        return tables.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate
                    (R.layout.catering_open_table_grid_item, parent, false);
        }
//        RelativeLayout rl_backGroup = BaseViewHolder.get(convertView, R.id.rl_tableItem_catering);
        ImageView iv = BaseViewHolder.get(convertView, R.id.iv_item);
        FrameLayout flReserve = BaseViewHolder.get(convertView, R.id.fl_reserve_size_item);
        TextView tv = BaseViewHolder.get(convertView, R.id.tv_item);
        DinnerTable item = tables.get(position);
        if(item.getTableReserveList()!=null && item.getTableReserveList().size()>0){
            flReserve.setVisibility(View.VISIBLE);
        }else{
            flReserve.setVisibility(View.GONE);
        }
        if(item.getStatus() == CateringPosConstant.CATERING_TABLE_STATUS_USE){
            iv.setBackgroundColor(context.getResources().getColor(R.color.colorUseTable));
            tv.setText(item.getId()+"号 "
                    +item.getSize() +"人桌 "
                    + CateringPosConstant.CATERING_TABLE_STATUS_USE_STR);
        }else if(item.getStatus() == CateringPosConstant.CATERING_TABLE_STATUS_USED){
            iv.setBackgroundColor(context.getResources().getColor(R.color.colorUsedTable));
            tv.setText(item.getId()+"号 "
                    +item.getSize() +"人桌 "
                    + CateringPosConstant.CATERING_TABLE_STATUS_USED_STR);
        }else if(item.getStatus() == CateringPosConstant.CATERING_TABLE_STATUS_SCHEDULED){
            iv.setBackgroundColor(context.getResources().getColor(R.color.colorScheduledTable));
            tv.setText(item.getId()+"号 "
                    +item.getSize() +"人桌 "
                    + CateringPosConstant.CATERING_TABLE_STATUS_SCHEDULED_STR);
        }else if(item.getStatus() == CateringPosConstant.CATERING_TABLE_STATUS_STOP){
            iv.setBackgroundColor(context.getResources().getColor(R.color.colorStopTable));
            tv.setText(item.getId()+"号 "
                    +item.getSize() +"人桌 "
                    + CateringPosConstant.CATERING_TABLE_STATUS_STOP_STR);
        }else{
//            if(item.getTableReserveList()!=null && item.getTableReserveList().size()>0){
//                flReserve.setVisibility(View.VISIBLE);
//            }else{
//                flReserve.setVisibility(View.GONE);
//            }
            iv.setBackgroundColor(context.getResources().getColor(R.color.main_line_interval));
            tv.setText(item.getId()+"号 "
                       +item.getSize() +"人桌 "
                       + CateringPosConstant.CATERING_TABLE_STATUS_FULL_STR);
//            if(mFlag){
//                tv.setTextColor(context.getResources().getColor(R.color.pay_select_text) );
//            }else if(!mFlag){
//                iv.setBackgroundResource(imgs.get(position));
//                tv.setTextColor(context.getResources().getColor(R.color.pay_no_select_text) );
//            }
        }
        return convertView;
    }
}
